<?php

namespace app\api\model;

use think\Model;

class UserWallet extends Model
{


    // 表名
    protected $name = 'user_wallet';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';


    /**
     * 推广中心
     */
    public function promotion($user_id)
    {
        $data = [];
        $invitation_code = model('user')->where('id', $user_id)->value('user_invitation_code');
        $data['gold_coin'] = $this->where(['type' => 5, 'user_id' => $user_id])->sum('gold_coin');
        $data['invitation_list'] = model('user')
            ->alias('a')
            ->join('user_info b', 'a.id = b.user_id')
            ->where('a.invitation_code', $invitation_code)
            ->field("b.avatar,b.username,FROM_UNIXTIME(b.createtime,'%Y-%m-%d %H:%i') as createtime")
            ->select();
        $data['invitation_num'] = count($data['invitation_list']);
        $data['invitation_code'] = $invitation_code;
        return $data;
    }
}